package com.example.senior_bug.controller;

import com.example.senior_bug.EntityClass.Comment;
import com.example.senior_bug.EntityClass.Order;
import com.example.senior_bug.ToolClass.Result;
import com.example.senior_bug.Service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/Order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    //根据用户名获取订单列表
    @RequestMapping("/getOrdersByCustomerName")
    public Result GetOrderByCustomerName(@RequestParam String CustomerName) {
        return orderService.getOrderByCustomerName(CustomerName);
    }

    //店铺订单列表
    @RequestMapping("/getOrdersByStoreName")
    public Result GetOrdersByStoreName(@RequestParam String StoreName) {
        return orderService.getOrderByStoreName(StoreName);
    }

    //用户下订单
    @RequestMapping(value = "/orderNewOrder", method = RequestMethod.POST, produces = "application/json")
    public Result OrderNewOrder(@RequestBody Order order, @RequestParam int addressId) {
        return orderService.orderNewOrder(order, addressId);
    }

    //订单详情
    @RequestMapping(value = "/getOrderById")
    public Result GetOrderById(@RequestParam int Id) {
        return orderService.getOrderById(Id);
    }

    //商家填写物流单号并修改状态
    @RequestMapping(value = "/AddLogisticsOrder")
    public Result AddLogisticsOrder(@RequestParam String LogisticsOrder,
                                    @RequestParam String Logistic, @RequestParam int orderId,
                                    @RequestParam int ReturnAddressId) {
        return orderService.AddLogisticsOrder(LogisticsOrder, Logistic, orderId, ReturnAddressId);
    }

    //用户填写物流单号并修改状态
    @RequestMapping(value = "/AddReturnLogisticsOrder")
    public Result AddReturnLogisticsOrder(@RequestParam String ReturnLogisticsOrder,
                                          @RequestParam String LogisticReturn, @RequestParam int orderId) {
        return orderService.AddReturnLogisticsOrder(ReturnLogisticsOrder, LogisticReturn, orderId);
    }

    //用户收货修改状态
    @RequestMapping(value = "/Received")
    public Result ReceivedOrder(@RequestParam int orderId) {
        return orderService.ReceivedOrder(orderId);
    }

    //用户直接购买修改状态
    @RequestMapping(value = "/Purchase")
    public Result PurchaseSKU(@RequestParam int orderId) {
        return orderService.PurchaseSKU(orderId);
    }

    //用户评价商品
    @RequestMapping(value = "/Comment", method = RequestMethod.POST, produces = "application/json")
    public Result AddComment(@RequestBody Comment comment, @RequestParam int orderId) {
        return orderService.AddComment(comment, orderId);
    }

    //商家确认收货
    @RequestMapping("/BusinessReceived")
    public Result BusinessReceived(@RequestParam int orderId) {
        return orderService.Received(orderId);
    }
}
